<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="危害名称" prop="harmId">
        <el-select v-model="queryParams.harmId" filterable>
          <el-option
              v-for="item in baseharmList"
              :key="item.id"
              :label="item.hamName"
              :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="在岗状态" prop="workStatus">
        <el-select v-model="queryParams.workStatus" placeholder="请选择在岗状态" clearable>
          <el-option
            v-for="dict in dict.type.dime_physical_work"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="启用" prop="isValid">
        <!--        <el-radio-group v-model="queryParams.isValid">-->
        <!--          <el-radio :label="1">是</el-radio>-->
        <!--          <el-radio :label="0">否</el-radio>-->
        <!--        </el-radio-group>-->
        <el-switch
          v-model="queryParams.isValid"
          active-color="#13ce66"
          inactive-color="#ff4949"
          :active-value="1"
          :inactive-value="0">
        </el-switch>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['basic:baseoccupationcriterion:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['basic:baseoccupationcriterion:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['basic:baseoccupationcriterion:remove']"
        >禁用
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['basic:baseoccupationcriterion:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="baseoccupationcriterionList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="" align="center" prop="id" />-->
      <!--      <el-table-column label="危害编码" align="center" prop="harmId" />-->
      <el-table-column label="危害名称" width="300" align="center" prop="harmName"/>
      <el-table-column label="在岗状态" align="center" prop="workStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.dime_physical_work" :value="scope.row.workStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="排序" align="center" prop="sn"/>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="启用" align="center">
        <!--        <template slot-scope="scope">{{-->
        <!--            scope.row.isValid ? "是" : "否"-->
        <!--          }}-->
        <!--        </template>-->
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.isValid"
            active-color="#13ce66"
            inactive-color="#ff4949"
            :active-value="1"
            :inactive-value="0"
            disabled>
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleSearch(scope.row)"
          >查看
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['basic:baseoccupationcriterion:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['basic:baseoccupationcriterion:remove']"
          >禁用
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改职业监护标准对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="危害名称" prop="harmId">
          <el-select v-model="form.harmId" filterable placeholder="请选择危害" style="width: 100%">
            <el-option
              v-for="item in baseharmList"
              :key="item.id"
              :label="item.hamName"
              :value="item.id"
              @click.native="setHarmName(item.hamName)"
            ></el-option>
          </el-select>
        </el-form-item>
        <!--        <el-form-item label="危害名称" prop="harmName">-->
        <!--          <el-input v-model="form.harmName" placeholder="请输入危害名称" />-->
        <!--        </el-form-item>-->
        <el-form-item label="在岗状态" prop="workStatus">
          <el-select v-model="form.workStatus" filterable placeholder="请选择在岗状态" style="width: 100%">
            <el-option
              v-for="dict in dict.type.dime_physical_work"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="排序" prop="sn">
          <el-input v-model="form.sn" @input="(v)=>(form.sn=v.replace(/[^\d]/g,''))" maxlength="8"
                    placeholder="请输入排序"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="启用" prop="isValid">
          <!--          <el-radio-group v-model="form.isValid">-->
          <!--            <el-radio :label="1">是</el-radio>-->
          <!--            <el-radio :label="0">否</el-radio>-->
          <!--          </el-radio-group>-->
          <el-switch
            v-model="form.isValid"
            active-color="#13ce66"
            inactive-color="#ff4949"
            :active-value="1"
            :inactive-value="0">
          </el-switch>
        </el-form-item>

        <!--        <el-row style="margin-left: 30px;margin-bottom:60px">-->
        <!--          <el-tabs v-model="activeName" style="height: 300px">-->
        <!--            <el-tab-pane label="监护标准对应必检项目" name="first" >-->
        <!--              <div class="button-container" align="right" style="margin-right: 6px">-->
        <!--                <el-button-->
        <!--                  class="filter-item"-->
        <!--                  size="mini"-->
        <!--                  plain-->
        <!--                  type="primary"-->
        <!--                  icon="el-icon-plus"-->
        <!--                  @click="handleCreateCombCriterion"-->
        <!--                >新增-->
        <!--                </el-button>-->
        <!--                <el-button-->
        <!--                  class="filter-item"-->
        <!--                  size="mini"-->
        <!--                  plain-->
        <!--                  type="danger"-->
        <!--                  icon="el-icon-delete"-->
        <!--                  :disabled="multipleCombSelection"-->
        <!--                  @click="handleMutipleDeleteCombCriterion"-->
        <!--                >批量删除-->
        <!--                </el-button>-->
        <!--              </div>-->
        <!--              <el-table-->
        <!--                id="combTable"-->
        <!--                border-->
        <!--                stripe-->
        <!--                :data="form.dimeBasecombcriterionList"-->
        <!--                :row-class-name="tableRowClassName"-->
        <!--                size="small"-->
        <!--                height="300px"-->
        <!--                style="width: 99%; margin-left: 4px"-->
        <!--                @selection-change="handleCombSelectionChange"-->
        <!--              >-->
        <!--                <el-table-column type="selection" width="40" align="center" />-->
        <!--                <el-table-column label="项目名称" width="250" align="center" prop="combId" >-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <virtual-select-->
        <!--                               v-model="scope.row.combId"-->
        <!--                               :list="basecombList"-->
        <!--                               clearable-->
        <!--                               filterable-->
        <!--                               placeholder="请选择项目"-->
        <!--                               label="combName"-->
        <!--                               value="id"-->
        <!--                               :keeps-params="10"-->
        <!--                               :is-concat="false"-->
        <!--                               :is-multiple="false"-->
        <!--                               :is-right="false "-->
        <!--                    >-->
        <!--                    </virtual-select>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="靶器官" width="150" align="center" prop="target">-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-input-->
        <!--                      v-model="scope.row.target"-->
        <!--                      size="mini"-->
        <!--                      type="text"-->
        <!--                      clearable-->
        <!--                    ></el-input>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="备注" width="170" align="center" prop="remark">-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-input-->
        <!--                      v-model="scope.row.remark"-->
        <!--                      size="mini"-->
        <!--                      type="text"-->
        <!--                      clearable-->
        <!--                    ></el-input>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="排序" width="103" align="center" prop="sn">-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-input-->
        <!--                      v-model="scope.row.sn"-->
        <!--                      size="mini"-->
        <!--                      type="text"-->
        <!--                      clearable-->
        <!--                      @input="(v)=>(scope.row.sn=v.replace(/[^\d]/g,''))"-->
        <!--                      maxlength="8"-->
        <!--                    ></el-input>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="必选" width="50" align="center" prop="required">-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-checkbox-->
        <!--                      true-label="1"-->
        <!--                      false-label="0"-->
        <!--                      v-model="scope.row.required"-->
        <!--                    ></el-checkbox>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="启用" width="62" align="center" prop="isValid">-->
        <!--&lt;!&ndash;                  <template slot-scope="scope">&ndash;&gt;-->
        <!--&lt;!&ndash;                    <el-checkbox&ndash;&gt;-->
        <!--&lt;!&ndash;                      :true-label="1"&ndash;&gt;-->
        <!--&lt;!&ndash;                      :false-label="0"&ndash;&gt;-->
        <!--&lt;!&ndash;                      v-model="scope.row.isValid"&ndash;&gt;-->
        <!--&lt;!&ndash;                    ></el-checkbox>&ndash;&gt;-->
        <!--&lt;!&ndash;                  </template>&ndash;&gt;-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-switch-->
        <!--                      v-model="scope.row.isValid"-->
        <!--                      active-color="#13ce66"-->
        <!--                      inactive-color="#ff4949"-->
        <!--                      :active-value="1"-->
        <!--                      :inactive-value="0">-->
        <!--                    </el-switch>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="操作" width="80" align="center">-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-button-->
        <!--                      type="danger"-->
        <!--                      size="mini"-->
        <!--                      icon="el-icon-delete"-->
        <!--                      @click="handleCombCriterionDelete(scope.$index)"-->
        <!--                    />-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--              </el-table>-->
        <!--            </el-tab-pane>-->

        <!--            <el-tab-pane label="监护标准对应禁忌症" name="second">-->
        <!--              <div class="button-container" align="right" style="margin-right: 6px">-->
        <!--                <el-button-->
        <!--                  class="filter-item"-->
        <!--                  size="mini"-->
        <!--                  plain-->
        <!--                  type="primary"-->
        <!--                  icon="el-icon-plus"-->
        <!--                  @click="handleCreateContraindicationCriterion"-->
        <!--                >新增-->
        <!--                </el-button>-->
        <!--                <el-button-->
        <!--                  class="filter-item"-->
        <!--                  size="mini"-->
        <!--                  plain-->
        <!--                  type="danger"-->
        <!--                  icon="el-icon-delete"-->
        <!--                  :disabled="multipleConSelection"-->
        <!--                  @click="handleMutipleDeleteCon"-->
        <!--                >批量删除-->
        <!--                </el-button>-->
        <!--              </div>-->
        <!--              <el-table-->
        <!--                border-->
        <!--                stripe-->
        <!--                :data="form.dimeBasecontraindicationcriterionList"-->
        <!--                :row-class-name="tableRowClassName"-->
        <!--                size="small"-->
        <!--                height="300px"-->
        <!--                style="width: 99%; margin-left: 4px"-->
        <!--                @selection-change="handleConSelectionChange"-->
        <!--              >-->
        <!--                <el-table-column type="selection" width="40" align="center" />-->
        <!--                <el-table-column label="禁忌症名称" align="center" prop="cationcriterionId" width="300">-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <virtual-select-->
        <!--                      v-model="scope.row.cationcriterionId"-->
        <!--                      :list="basecontraindicationList"-->
        <!--                      clearable-->
        <!--                      filterable-->
        <!--                      placeholder="请选择禁忌症"-->
        <!--                      label="name"-->
        <!--                      value="id"-->
        <!--                      :keeps-params="10"-->
        <!--                      :is-concat="false"-->
        <!--                      :is-multiple="false"-->
        <!--                      :is-right="false "-->
        <!--                    >-->
        <!--                    </virtual-select>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="备注" align="center" prop="remark" width="300">-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-input-->
        <!--                      v-model="scope.row.remark"-->
        <!--                      size="mini"-->
        <!--                      type="text"-->
        <!--                      clearable-->
        <!--                    ></el-input>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="排序" align="center" prop="sn" width="138">-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-input-->
        <!--                      v-model="scope.row.sn"-->
        <!--                      size="mini"-->
        <!--                      type="text"-->
        <!--                      clearable-->
        <!--                      @input="(v)=>(scope.row.sn=v.replace(/[^\d]/g,''))"-->
        <!--                      maxlength="8"-->
        <!--                    ></el-input>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="启用" width="62" align="center" prop="isValid">-->
        <!--&lt;!&ndash;                  <template slot-scope="scope">&ndash;&gt;-->
        <!--&lt;!&ndash;                    <el-checkbox&ndash;&gt;-->
        <!--&lt;!&ndash;                      :true-label="1"&ndash;&gt;-->
        <!--&lt;!&ndash;                      :false-label="0"&ndash;&gt;-->
        <!--&lt;!&ndash;                      v-model="scope.row.isValid"&ndash;&gt;-->
        <!--&lt;!&ndash;                    ></el-checkbox>&ndash;&gt;-->
        <!--&lt;!&ndash;                  </template>&ndash;&gt;-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-switch-->
        <!--                      v-model="scope.row.isValid"-->
        <!--                      active-color="#13ce66"-->
        <!--                      inactive-color="#ff4949"-->
        <!--                      :active-value="1"-->
        <!--                      :inactive-value="0">-->
        <!--                    </el-switch>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="操作" width="80" align="center">-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-button-->
        <!--                      type="danger"-->
        <!--                      size="mini"-->
        <!--                      icon="el-icon-delete"-->
        <!--                      @click="handleContraindicationCriterionDelete(scope.$index)"-->
        <!--                    />-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--              </el-table>-->
        <!--            </el-tab-pane>-->

        <!--            <el-tab-pane label="监护标准对应职业病" name="third">-->
        <!--              <div class="button-container" align="right" style="margin-right: 6px">-->
        <!--                <el-button-->
        <!--                  class="filter-item"-->
        <!--                  size="mini"-->
        <!--                  plain-->
        <!--                  type="primary"-->
        <!--                  icon="el-icon-plus"-->
        <!--                  @click="handleCreateOccupationCriterion"-->
        <!--                >新增-->
        <!--                </el-button>-->
        <!--                <el-button-->
        <!--                  class="filter-item"-->
        <!--                  size="mini"-->
        <!--                  plain-->
        <!--                  type="danger"-->
        <!--                  icon="el-icon-delete"-->
        <!--                  :disabled="multipleOccSelection"-->
        <!--                  @click="handleMutipleDeleteOcc"-->
        <!--                >批量删除-->
        <!--                </el-button>-->
        <!--              </div>-->
        <!--              <el-table-->
        <!--                border-->
        <!--                stripe-->
        <!--                :data="form.dimeBaseoccupationcriterionList"-->
        <!--                :row-class-name="tableRowClassName"-->
        <!--                size="small"-->
        <!--                height="200px"-->
        <!--                style="width: 99%; margin-left: 4px"-->
        <!--                @selection-change="handleOccSelectionChange"-->
        <!--              >-->
        <!--                <el-table-column type="selection" width="40" align="center" />-->
        <!--                <el-table-column label="职业病名称" align="center" prop="occupationaldiseaeId" width="210">-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <virtual-select-->
        <!--                      v-model="scope.row.occupationaldiseaeId"-->
        <!--                      :list="baseoccupationaldiseaseList"-->
        <!--                      clearable-->
        <!--                      filterable-->
        <!--                      placeholder="请选择职业病"-->
        <!--                      label="name"-->
        <!--                      value="id"-->
        <!--                      :keeps-params="10"-->
        <!--                      :is-concat="false"-->
        <!--                      :is-multiple="false"-->
        <!--                      :is-right="false "-->
        <!--                    >-->
        <!--                    </virtual-select>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="备注" align="center" prop="remark" width="200">-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-input-->
        <!--                      v-model="scope.row.remark"-->
        <!--                      size="mini"-->
        <!--                      type="text"-->
        <!--                      clearable-->
        <!--                    ></el-input>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="排序" align="center" prop="sn" width="105">-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-input-->
        <!--                      v-model="scope.row.sn"-->
        <!--                      size="mini"-->
        <!--                      type="text"-->
        <!--                      clearable-->
        <!--                      @input="(v)=>(scope.row.sn=v.replace(/[^\d]/g,''))"-->
        <!--                      maxlength="8"-->
        <!--                    ></el-input>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="启用" width="62" align="center" prop="isValid">-->
        <!--&lt;!&ndash;                  <template slot-scope="scope">&ndash;&gt;-->
        <!--&lt;!&ndash;                    <el-checkbox&ndash;&gt;-->
        <!--&lt;!&ndash;                      :true-label="1"&ndash;&gt;-->
        <!--&lt;!&ndash;                      :false-label="0"&ndash;&gt;-->
        <!--&lt;!&ndash;                      v-model="scope.row.isValid"&ndash;&gt;-->
        <!--&lt;!&ndash;                    ></el-checkbox>&ndash;&gt;-->
        <!--&lt;!&ndash;                  </template>&ndash;&gt;-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-switch-->
        <!--                      v-model="scope.row.isValid"-->
        <!--                      active-color="#13ce66"-->
        <!--                      inactive-color="#ff4949"-->
        <!--                      :active-value="1"-->
        <!--                      :inactive-value="0">-->
        <!--                    </el-switch>-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--                <el-table-column label="操作" width="80" align="center">-->
        <!--                  <template slot-scope="scope">-->
        <!--                    <el-button-->
        <!--                      type="danger"-->
        <!--                      size="mini"-->
        <!--                      icon="el-icon-delete"-->
        <!--                      @click="handleOccupationCriterionDelete(scope.$index)"-->
        <!--                    />-->
        <!--                  </template>-->
        <!--                </el-table-column>-->
        <!--              </el-table>-->
        <!--            </el-tab-pane>-->

        <!--          </el-tabs>-->
        <!--        </el-row>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listBaseoccupationcriterion,
  getBaseoccupationcriterion,
  delBaseoccupationcriterion,
  addBaseoccupationcriterion,
  updateBaseoccupationcriterion
} from "@/api/basic/baseoccupationcriterion";
import {listBaseoccupationaldiseae} from "@/api/basic/baseoccupationaldiseae";
import {listBasecontraindication} from "@/api/basic/basecontraindication";
import {listBasecombcriterion} from "@/api/basic/basecombcriterion";
import {listBasecomb} from "@/api/basic/basecomb";
import {listBaseharm} from "@/api/basic/baseharm";
import VirtualSelect from '@/views/components/Select'
import router from "@/router/index"
import dictTag from "@/components/DictTag/index.vue";

export default {
  name: "Baseoccupationcriterion",
  components: {VirtualSelect},
  dicts: ['dime_physical_work'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      routes: [],
      // 非多个禁用
      multiple: true,
      // 非多个禁用(对应必检项目)
      multipleCombSelection: true,
      // 非多个禁用(对应禁忌症)
      multipleConSelection: true,
      // 非多个禁用(对应职业病)
      multipleOccSelection: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 职业监护标准表格数据
      baseoccupationcriterionList: [],
      // 监护标准对应职业病表格数据
      baseoccupationaldiseaseList: [],
      // 监护标准对应禁忌症表格数据
      basecontraindicationList: [],
      // 职业监护标准必检项目表格数据
      basecombcriterionList: [],
      // 危害因素管理表格数据
      baseharmList: [],
      // 项目组合管理表格数据
      basecombList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层
      search: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        harmId: null,
        harmName: null,
        workStatus: null,
        isValid: 1
      },
      //左边菜单
      menuList: [
        {id: 1, path: 'basecombcriterion', name: '监护标准对应项目'},
        {id: 2, path: 'basecontraindicationcriterion', name: '监护标准对应禁忌症'},
        {id: 3, path: 'baseoccupationaldiseasecriterion', name: '监护标准对应职业病'}
      ],
      // 表单参数
      form: {},
      //默认
      activeName: "first",
      // 表单校验
      rules: {
        // harmId: [
        //   { required: true, message: "危害编码不能为空", trigger: "blur" }
        // ],
        harmId: [
          {required: true, message: "危害编码不能为空", trigger: "change"}
        ],
        workStatus: [
          {required: true, message: "在岗状态不能为空", trigger: "change"}
        ]
      }
    };
  },
  created() {
    this.getList();
    listBaseoccupationaldiseae({
      pageNum: 1,
      pageSize: 3000
    }).then(response => {
      this.baseoccupationaldiseaseList = response.rows;
      this.baseoccupationaldiseaseList.forEach(item => {
        item.key = item.id
        item.label = item.name
      })
    });
    // listBasecontraindication({
    //   pageNum: 1,
    //   pageSize: 3000
    // }).then(response => {
    //   this.basecontraindicationList = response.rows;
    //   this.basecontraindicationList.forEach(item => {
    //     item.key = item.id
    //     item.label = item.name
    //   })
    // });
    // listBasecombcriterion({
    //   pageNum: 1,
    //   pageSize: 3000
    // }).then(response => {
    //   this.basecombcriterionList = response.rows;
    // });
    listBaseharm({
      pageNum: 1,
      pageSize: 3000
    }).then(response => {
      this.baseharmList = response.rows;
    });
    // listBasecomb({
    //   pageNum: 1,
    //   pageSize: 4000
    // }).then(response => {
    //   this.basecombList = response.rows;
    // });
  },
  methods: {
    /** 查询职业监护标准列表 */
    getList() {
      this.loading = true;
      listBaseoccupationcriterion(this.queryParams).then(response => {
        this.baseoccupationcriterionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    setHarmName(hamName) {
      this.form.harmName = hamName;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        harmId: null,
        harmName: null,
        workStatus: null,
        sn: null,
        remark: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        isValid: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //row-class-name添加下标
    tableRowClassName(row, index) {
      row.row.index = row.rowIndex;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 多选框选中数据(对应必检项目)
    handleCombSelectionChange(rows) {
      this.selectedCombList = [];
      rows.forEach(item => {
        this.selectedCombList.push(item.index)
      })
      this.multipleCombSelection = !this.selectedCombList.length
    },
    // 多选框选中数据(对应禁忌症)
    handleConSelectionChange(rows) {
      this.selectedConList = [];
      rows.forEach(item => {
        this.selectedConList.push(item.index)
      })
      this.multipleConSelection = !this.selectedConList.length
    },
    // 多选框选中数据(对应职业病)
    handleOccSelectionChange(rows) {
      this.selectedOccList = [];
      rows.forEach(item => {
        this.selectedOccList.push(item.index)
      })
      this.multipleOccSelection = !this.selectedOccList.length
    },
    /** 查看按钮操作 */
    handleSearch(row) {
      this.reset();
      const id = row.id

      this.$router.push({
        path: '/searchbaseoccupationcriterion',
        query: {
          id: id,
          harmName: row.harmName,
          workStatus: row.workStatus
        }
      })
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.form.isValid = 1;
      this.form.dimeBasecombcriterionList = [];
      this.form.dimeBasecontraindicationcriterionList = [];
      this.form.dimeBaseoccupationcriterionList = [];
      this.title = "添加职业监护标准";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true
      this.reset();
      const id = row.id || this.ids
      getBaseoccupationcriterion(id).then(response => {
        this.form.dimeBasecontraindicationcriterionList = response.data.dimeBasecontraindicationcriterionList;
        this.form.dimeBaseoccupationcriterionList = response.data.dimeBaseoccupationcriterionList;
        this.form.dimeBasecombcriterionList = response.data.dimeBasecombcriterionList;
        this.form = response.data;
        this.open = true;
        this.title = "修改职业监护标准";
        this.loading = false
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBaseoccupationcriterion(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBaseoccupationcriterion(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    handleCreateCombCriterion() {
      let newValue = {
        id: "",
        combId: "",
        combName: "",
        target: "",
        required: "1",
        sn: "",
        remark: "",
        isValid: 1
      };
      //添加新的行数
      this.form.dimeBasecombcriterionList.push(newValue);
      return this.$modal.msgSuccess("新增成功");
    },

    handleCreateOccupationCriterion() {
      let newValue = {
        id: "",
        occupationaldiseaeId: "",
        occupationaldiseaeName: "",
        required: "",
        sn: "",
        remark: "",
        isValid: 1
      };
      //添加新的行数
      this.form.dimeBaseoccupationcriterionList.push(newValue);
      return this.$modal.msgSuccess("新增成功");
    },

    handleCreateContraindicationCriterion() {
      let newValue = {
        id: "",
        cationcriterionId: "",
        cationcriterionName: "",
        required: "",
        sn: "",
        remark: "",
        isValid: 1
      };
      //添加新的行数
      this.form.dimeBasecontraindicationcriterionList.push(newValue);
      return this.$modal.msgSuccess("新增成功");
    },

    selectCombCriterion(params) {
      const {value, label} = params;
      this.form.combId = value;
      this.form.combName = label;
    },
    selectOccupationCriterion(index) {
      this.form.occupationaldiseaeId = this.baseoccupationaldiseaseList[index].id;
      this.form.occupationaldiseaeName = this.baseoccupationaldiseaseList[index].name;
    },
    selectContraindicationCriterion(index) {
      this.form.cationcriterionId = this.basecontraindicationList[index].id;
      this.form.cationcriterionName = this.basecontraindicationList[index].name;
    },

    //过滤相同项
    filterHasSameArr(arr1, arr2) {
      return arr1.filter((item, index) => !arr2.includes(index));
    },

    //批量删除对应必检项目
    handleMutipleDeleteCombCriterion() {
      this.$modal.confirm('是否确认批量删除数据项？').then(() => {
        console.log(this.selectedCombList)
        this.form.dimeBasecombcriterionList = this.filterHasSameArr(this.form.dimeBasecombcriterionList, this.selectedCombList)
        return this.$modal.msgSuccess("删除成功");
      })
    },

    //批量删除对应禁忌症
    handleMutipleDeleteCon() {
      this.$modal.confirm('是否确认批量删除数据项？').then(() => {
        this.form.dimeBasecontraindicationcriterionList = this.filterHasSameArr(this.form.dimeBasecontraindicationcriterionList, this.selectedConList)
        return this.$modal.msgSuccess("删除成功");
      })
    },

    //批量删除对应职业病
    handleMutipleDeleteOcc() {
      this.$modal.confirm('是否确认批量删除数据项？').then(() => {
        this.form.dimeBaseoccupationcriterionList = this.filterHasSameArr(this.form.dimeBaseoccupationcriterionList, this.selectedOccList)
        return this.$modal.msgSuccess("删除成功");
      })
    },

    //删除对应必检项目
    handleCombCriterionDelete(index) {
      this.$modal.confirm('是否确认删除该数据项？').then(() => {
        this.form.dimeBasecombcriterionList.splice(index, 1);
        return this.$modal.msgSuccess("删除成功");
      })
    },

    //删除对应禁忌症
    handleContraindicationCriterionDelete(index) {
      this.$modal.confirm('是否确认删除该数据项？').then(() => {
        this.form.dimeBasecontraindicationcriterionList.splice(index, 1);
        return this.$modal.msgSuccess("删除成功");
      })
    },

    //删除对应职业病
    handleOccupationCriterionDelete(index) {
      this.$modal.confirm('是否确认删除该数据项？').then(() => {
        this.form.dimeBaseoccupationcriterionList.splice(index, 1);
        return this.$modal.msgSuccess("删除成功");
      })
    },

    /** 禁用按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认禁用职业监护标准编号为"' + ids + '"的数据项？').then(function () {
        return delBaseoccupationcriterion(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("禁用成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('basic/baseoccupationcriterion/export', {
        ...this.queryParams
      }, `baseoccupationcriterion_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
